from flask import Blueprint,g,render_template,json,request
import Model.Market as m
import time,Config

page = Blueprint('index',__name__)

@page.route('/')
def index():
    return render_template("index.html")

@page.route('/dailyIncome',methods=['POST'])
def dailyIncome():
    startDate = request.form.get('startDate')
    endDate = request.form.get('endDate')
    data=m.MarketModel().DataQueryRedisByInterval(key='IncomeByInterval',item1=startDate,item2=endDate)
    return json.jsonify(data)

@page.route('/GoodsMarketByDay',methods=['POST'])
def dailyGoodsMarket():
    date = request.form.get('date')
    time.sleep(0.5)
    data=m.MarketModel().DataQueryRedisByDay1(key='GoodsMarketByDay',item1=date)
    return json.jsonify(data)

@page.route('/goodsStat')
def goodsStat():
    # time.sleep(2)
    data = m.MarketModel().DataQueryMongoByGoodsTotal()
    return json.jsonify(data)

@page.route('/goodsStatBar')
def goodsStatBar():
    # time.sleep(3)
    data = m.MarketModel().DataQueryMongoByGoodsTotalOrder()
    return json.jsonify(data)

@page.route('/getFirstDay')
def getFirstDay():
    # time.sleep(4)
    data=[item for item in m.MarketModel().firstDayQuery()]
    return json.jsonify(data)

@page.route('/get3DData')
def get3DData():
    # time.sleep(5)
    data=[item for item in m.MarketModel().Daily3DMarketQuery()]
    return json.jsonify(data)